package cn.com.lms.business.organization.persistence.repository;

import cn.com.lms.business.organization.persistence.entity.FbSysDepartmentEntity;
import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface FbSysDepartmentRepository extends BaseRepository<FbSysDepartmentEntity, Long> {

    List<FbSysDepartmentEntity> findAllByEnabled(Boolean enabled);

    /**
     * 设置部门全名称字段值
     */
    @Query(value = "update bnz_sys_department set full_name=queryDeptFullName(id)", nativeQuery = true)
    @Modifying
    void updateFullName();

    /**
     * 查询部门下的所有员工
     *
     * @param deptId
     * @return
     */
    @Query(value = "select   s.dept_id deptId,s.id userId,s.cname userName,d.full_name deptName from bnz_sys_user s left join bnz_sys_department d on s.dept_id=d.id  where (dept_id in(:deptId) or job_type_name in(:jobType)) and personnel=1", nativeQuery = true)
    List<Map<String, Object>> querySysUserByDeptId(@Param("deptId") List<Long> deptId, @Param("jobType") List<String> jobType);
}
